import java.util.Arrays;

///encapsulates a move

///in general, you should regard this as an opaque structure that you obtain
///from FindPossibleMoves, and provide to DoMove, or to the constructor of Board
///that takes a move
///
///The functions IsPass and IsEOG() can however be useful.
///
///The rest of the interface you can probably ignore it.
public class Move {

    static final Move cPass=new Move(-1,-1,0);   ///< a pass
    static final Move cEOG=new Move(-2,-2,0); ///< end of game indicator

    ///constructs a move
    Move(int pR,int pC,int pWho)
    {
        mR=pR;
        mC=pC;
        mWho=pWho;
    }

    ///reconstructs the move from a string
        
    ///\param pString a string, which should have been previously generated
    ///by ToString(), or obtained from the server
    Move(String pString,int pWho)
    {
        mWho=pWho;
        
        String[] lTokens=pString.split("[ ]+");

        mR=Integer.parseInt(lTokens[0]);
        mC=Integer.parseInt(lTokens[1]);
    }

    ///returns true if the movement is a pass
    boolean IsPass()              {     return (mR==-1); }
    ///returns true if the movement marks end of game
    boolean IsEOG()            {   return (mR==-2);   }

    int Row()              {     return mR;                }
    int Col()              {     return mC;                }
    int Who()              {     return mWho;                }
        
    ///converts the move to a string so that it can be sent to the server
    String ToString()
    {
        StringBuffer lBuffer=new StringBuffer();

        lBuffer.append((int)mR);
        lBuffer.append(' ');
        lBuffer.append((int)mC);
        
        return lBuffer.toString();
    }

    private int mR,mC,mWho;
}
